/**
 * 
 */

package com.tenentia.pcmps.swm.business.implementation;

import org.apache.log4j.Logger;

import com.tenentia.pcmps.swm.Constants;
import com.tenentia.pcmps.swm.business.BusinessLogicException;
import com.tenentia.pcmps.swm.business.interfaces.PersonsManager;
import com.tenentia.pcmps.swm.data.DataAccessObjectsFactory;
import com.tenentia.pcmps.swm.data.beans.Person;
import com.tenentia.pcmps.swm.data.interfaces.PersonsDAO;

/**
 * 
 * @author tEnEntia, S.L.N.E.
 * 
 */
public class PersonsManagerImpl implements PersonsManager {

	private static final Logger LOGGER = Logger.getLogger(PersonsManagerImpl.class.getPackage().getName());

	/**
	 * 
	 */
	PersonsManagerImpl() {

		super();
	}

	@Override
	public void deleteInstance(Person person) throws BusinessLogicException {
		try {
			PersonsDAO personsDAO = (PersonsDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.PERSONS_DAO);
			personsDAO.deleteInstance(person);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

	@Override
	public Person getInstance(Person person) throws BusinessLogicException {

		try {
			PersonsDAO personsDAO = (PersonsDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.PERSONS_DAO);
			return personsDAO.getInstance(person);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
	}

	@Override
	public Person saveInstance(Person person) throws BusinessLogicException {
		LOGGER.debug(Constants.STRING_L4J_METHOD_BEGIN);
			
		try {
			PersonsDAO dataAccessObject = (PersonsDAO) DataAccessObjectsFactory.getInstance().createNewDataAccessObject(DataAccessObjectsFactory.PERSONS_DAO);
			person = dataAccessObject.saveInstance(person);
		} catch (Exception e) {
			LOGGER.error(e, e);
			throw new BusinessLogicException(e);
		}
		
		return person;
	}

	@Override
	public Person updateInstance(Person person) throws BusinessLogicException {

		// TODO Auto-generated method stub
		return null;
	}

}
